from django_filters import rest_framework as filters
from goods.models import Goods
from django.utils.translation import ugettext_lazy as _


class GoodsFilter(filters.FilterSet):
    """商品的过滤类"""
    # 指定字段以及字段上的行为，在shop_price上大于等于
    pricemin = filters.NumberFilter(field_name="shop_price", lookup_expr='gte', help_text=_('大于等于本店价格'))
    pricemax = filters.NumberFilter(field_name="shop_price", lookup_expr='lte', help_text=_('小于等于本店价格'))

    class Meta:
        model = Goods
        fields = ['pricemin', 'pricemax', 'name', 'is_hot', 'category']


class GoodsSearchFilter(filters.FilterSet):
    """商品搜索过滤"""

    class Meta:
        model = Goods
        fields = ['name', 'category']


class GoodsCategoryFilter(filters.Filter):
    """查找某一类目下面的商品"""

    class Meta:
        model = Goods
        fields = ['category',]
